; Music of Mad Balls (1988) (Ocean Software) (Jason C. Brooke)
; Ripped by Megachur the 17/12/2006

	write "MADBALLS.BIN"

music_date_rip	equ &11c6
music_adr	equ &0100	; &0000 relocated
first_theme	equ 0
last_theme	equ 1

	read "music_header_v1_0.asm"

;org #02bf
;db "This music module is the copyright of Jas.C.Brooke. Prepare to die!"

;init = 0,1

;
.play_music
;
.l0000
	sub a
.music_end equ $ + 1
.l0002 equ $ + 1
	cp #00
	push ix
	jr z,l0040
	ld b,a
	ld ix,l02bc
	ld hl,l0301
	dec (hl)
	jr nz,l0020
.l0013 equ $ + 1
	ld (hl),#01
	call l0163
	call l0161
	call l0161
	ld lx,l02bc	;#bc
.l0021 equ $ + 1
.l0020
	ld a,#00
	ld (l0308),a
	ld bc,l030a
	call l01e9
	ld (l0302),hl
	ld bc,l030b
	call l01e7
	ld (l0304),hl
	ld bc,l030c
	call l01e7
	ld (l0306),hl
.l0040
	ld hl,l02be
	ld a,#fe
	or (hl)
	dec l
	ld c,(hl)
	dec l
	rr c
	rla
	ld c,(hl)
	rr c
	rla
	ld c,a
	add a
	add a
	add a
	xor c
	ld (l0309),a
	sub a
.l005a equ $ + 1
	cp #00
	ld hl,l030e
.l005e
	ld c,a
	ld de,#0cf6
	jr z,l0069
	inc d
	inc l
	ld (l005a),a
.l0069
	ld a,#c0
.l006b
	ld b,#f4
	out (c),d
	ld b,e
	out (c),a
	rlca
	out (c),c
	dec b
	outd
	ld b,e
	out (c),a
	rrca
	out (c),c
	dec d
	jp p,l006b
	pop ix
	ret
;
.init_music
;
	push bc
	push de
	push hl
	push ix
	ld hl,l04c0
	ld b,#00
	ld c,a
	add a
	add c
	add a
	add c
	ld c,a
	add hl,bc
	ld a,(hl)
	inc hl
	ld (l0013),a
	ld ix,l02bc
	sub a
	ld (l0002),a
	inc a
	ld (l0301),a
	inc a
	ld c,a
.l00a9
	ld e,(hl)
	inc hl
	ld d,(hl)
	inc hl
	push hl
	ld (ix+#24),#01
	ld (ix+#42),b
	ld (ix+#3f),b
	ld (ix+#18),b
	ld (ix+#09),e
	ld (ix+#0c),d
	ld (ix+#0f),c
	ex de,hl
	ld e,(hl)
	inc l
	ld d,(hl)
	pop hl
	ld (ix+#03),e
	ld (ix+#06),d
	inc lx
	dec a
	jp p,l00a9
	ld (l0002),a
	pop ix
	pop hl
	pop de
	pop bc
	ret
	db #d4,#6e,#3f,#62,#65,#19,#4b,#76
	db #04,#31,#6f,#69
	ld hl,l0040
	ex (sp),hl
;
.stop_music
;
	sub a
	ld (l0002),a
	ld (l030a),a
	ld (l030b),a
	ld (l030c),a
	ret
	ld c,(ix+#0f)
	ld l,(ix+#09)
	ld h,(ix+#0c)
	add hl,bc
	ld a,(hl)
	inc l
	or (hl)
	jr nz,l010e
	sbc hl,bc
	ld c,b
.l010e
	ld d,(hl)
	dec l
	ld e,(hl)
	inc c
	inc c
	ld (ix+#0f),c
	jr l0176
	ld a,(de)
	inc de
	ld (ix+#3f),a
	jr l0176
	ld a,(de)
	inc de
	ld (ix+#1e),a
	set 3,(ix+#42)
	ld a,(de)
	inc de
	ld (ix+#21),a
	jr l0176
	ld a,(de)
	inc de
	ld (ix+#39),a
	ld a,(de)
	inc de
	ld (ix+#3c),a
	add a
	ld (ix+#36),a
	set 4,(ix+#42)
	jr l0176
	set 7,(ix+#42)
	set 6,(ix+#42)
	jr l0176
	ld (ix+#42),b
	jr l0176
	ld a,(de)
	inc de
	ld (l02a7),a
	set 2,(ix+#42)
	set 1,(ix+#42)
	jr l0176
.l0161
	inc lx
.l0163
	dec (ix+#24)
	ld a,(ix+#42)
	jr nz,l01a6
	and #30
	ld (ix+#42),a
	ld e,(ix+#03)
	ld d,(ix+#06)
.l0176
	ld a,(de)
	inc de
	cp #b0
	jr c,l019a
	add #20
	jr c,l018f
	add #20
	jr c,l0195
	ld c,a
	ld hl,l0362
	add hl,bc
	ld c,(hl)
	ld (ix+#18),c
	jr l0176
.l018f
	inc a
	ld (ix+#27),a
	jr l0176
.l0195
	ld (ix+#33),a
	jr l0176
.l019a
	or a
	jp p,l01b8
	ld c,a
	ld hl,l005e
	add hl,bc
	ld c,(hl)
	add hl,bc
	jp (hl)
.l01a6
	add a
	ret p
	sbc a
	or #01
	add (ix+#2a)
	ld (ix+#2a),a
	ret
	ld (ix+#30),#f0
	jr l01da
.l01b8
	ld (ix+#2a),a
	ld (ix+#12),b
	ld (ix+#15),b
	ld (ix+#30),b
	ld (ix+#2d),b
	ld c,(ix+#18)
	ld (ix+#1b),c
	ld c,b
	sub #54
	jr c,l01d7
	ld c,#02
	ld (l0021),a
.l01d7
	ld (ix+#00),c
.l01da
	ld a,(ix+#27)
	ld (ix+#24),a
	ld (ix+#06),d
	ld (ix+#03),e
	ret
.l01e7
	inc lx
.l01e9
	ld d,#00
	ld a,(ix+#30)
	cp #f0
	jr nc,l020d
	sub #10
	ld (ix+#30),a
	jr nc,l020d
	ld hl,l046a
	ld e,(ix+#33)
	add hl,de
	ld a,(hl)
	add (ix+#2d)
	ld e,a
	add hl,de
	ld a,(hl)
	inc (ix+#2d)
	ld (ix+#30),a
.l020d
	or #f0
	inc a
	add #0f
	jr c,l0215
	sub a
.l0215
	ld (bc),a
	ld hl,l0457
	ld e,(ix+#1b)
	inc e
	add hl,de
	ld a,(hl)
	or a
	jp p,l0228
	ld e,(ix+#18)
	and #7f
.l0228
	ld (ix+#1b),e
	add (ix+#2a)
	add (ix+#3f)
	add a
	ld hl,l0310
	ld e,a
	add hl,de
	ld e,(hl)
	inc l
	ld d,(hl)
	ld c,(ix+#42)
	bit 4,c
	jr z,l026c
	sub a
	or (ix+#39)
	jr nz,l0249
	inc a
	and c
.l0249
	ld b,(ix+#36)
	ld l,a
	ld a,(ix+#3c)
	bit 5,c
	jr nz,l025b
	sub l
	jr nz,l0261
	set 5,c
	jr l0261
.l025b
	add l
	cp b
	jr nz,l0261
	res 5,c
.l0261
	ld (ix+#3c),a
	srl b
	sub b
	ld l,a
	sbc a
	ld h,a
	add hl,de
	ex de,hl
.l026c
	ld a,c
	xor #01
	ld (ix+#42),a
	bit 3,c
	jr z,l0297
	ld b,(ix+#21)
	djnz l0294
	ld c,(ix+#1e)
	bit 7,c
	jr z,l0283
	dec b
.l0283
	ld l,(ix+#12)
	ld h,(ix+#15)
	add hl,bc
	ld (ix+#12),l
	ld (ix+#15),h
	add hl,de
	ex de,hl
	jr l0297
.l0294
	ld (ix+#21),b
.l0297
	cpl
	and #03
	ld a,(ix+#00)
	ld c,a
	res 0,c
	rra
	jr nz,l02aa
	ld hl,l0308
.l02a7 equ $ + 1
	ld (hl),#10
	or #01
.l02aa
	or c
	bit 2,(ix+#42)
	jr z,l02b5
	res 1,(ix+#42)
.l02b5
	ld (ix+#00),a
	ex de,hl
	ret
.l02be equ $ + 4
.l02bc equ $ + 2
	db #00,#00,#00,#00,#00,#54,#68,#69
	db #73,#20,#6d,#75,#73,#69,#63,#20
	db #6d,#6f,#64,#75,#6c,#65,#20,#69
	db #73,#20,#74,#68,#65,#20,#63,#6f
	db #70,#79,#72,#69,#67,#68,#74,#20
	db #6f,#66,#20,#4a,#61,#73,#2e,#43
	db #2e,#42,#72,#6f,#6f,#6b,#65,#2e
	db #20,#50,#72,#65,#70,#61,#72,#65
.l0301 equ $ + 7
	db #20,#74,#6f,#20,#64,#69,#65,#21
.l0309 equ $ + 7
.l0308 equ $ + 6
.l0306 equ $ + 4
.l0304 equ $ + 2
.l0302
	db #00,#00,#00,#00,#00,#00,#00,#00
.l030e equ $ + 4
.l030c equ $ + 2
.l030b equ $ + 1
.l030a
	db #00,#00,#00,#00,#00,#00
.l0310
	dw #0776,#070b,#06a6,#0646
	dw #05ec,#0597,#0547,#04fb
	dw #04b3,#0470,#0430,#03f4
	dw #03bb,#0385,#0353,#0323
	dw #02f6,#02cb,#02a3,#027d
	dw #0259,#0237,#0218,#01f9
	dw #01dd,#01c2,#01a9,#0191
	dw #017a,#0165,#0151,#013e
	dw #012c,#011b,#010b,#00fc
	dw #00ee,#00e1,#00d4,#00c8
.l0362 equ $ + 2
	dw #00bd,#00b2,#00a8,#009f
	dw #0096,#008d,#0085,#007e
	dw #0077,#0070,#006a,#0064
	dw #005e,#0059,#0054,#004f
	dw #004a,#0046,#0042,#003f
	dw #003b,#0038,#0034,#0031
	dw #002f,#002c,#0029,#0027
	dw #0025,#0023,#0021,#001f
	dw #001d,#001b,#001a,#0018
	dw #0017,#0016,#0014,#0013
	dw #0012,#0011,#0010,#000f
.l03b8
	dw l04d6,l04d8,l0505,l04d8
	dw l0609,l04d6,l04d8,l0505
	dw l04d8,l0609,l04d8,l04d8
	dw l0505,l04d8,l0609,l04d8
	dw l04d8,l0505,l04d8,l0609
	dw l04d6,l04d8,l0505,l04d8
	dw l0609,#0000
.l03ec
	dw l052c,l052c,l0651,l0651
	dw l05a1,#0000
.l03f8
	dw l059f,l059f,l05a1,l05a1
	dw l059f,#0000
.l0404
	dw l06b1,l06b1,l06b1,l06b1
	dw l0743,l0743,l0745,l0745
	dw l0759,l0743,l0743,l0745
	dw l0745,l0759,l07d5,l07d5
	dw l07d5,l07d5,#0000
.l042a
	dw l06d9,l06d9,l0700,l079a
	dw l0700,l079a,l07b4,l07b4
	dw #0000
.l043c
	dw l0726,l0726,l0726,l0726
	dw l06fd,l079a,l06fd,l079a
	dw l07b4,l07b4,#0000
.l0457 equ $ + 5
	db #00,#01,#05,#09,#0d,#0f,#80,#13
	db #0c,#10,#87,#10,#0c,#04,#87,#0c
	db #07,#00,#84,#00,#8c,#00,#04,#87
.l046a
	db #09,#13,#1a,#1c,#27,#2e,#2f,#34
	db #43,#0d,#0c,#0b,#0a,#39,#48,#47
	db #26,#25,#24,#f3,#0a,#0b,#1a,#19
	db #28,#47,#26,#f5,#7a,#79,#f8,#2b
	db #1a,#19,#98,#97,#96,#95,#94,#93
	db #92,#91,#f0,#0a,#19,#0a,#18,#17
	db #16,#15,#f4,#29,#28,#27,#16,#15
	db #14,#13,#f2,#0c,#1e,#0d,#0c,#0b
	db #2a,#49,#28,#27,#26,#25,#24,#23
	db #22,#21,#f0,#0a,#19,#08,#07,#f0
	db #1e,#0d,#1c,#0b,#1a,#f0
.l04c0
	db #04
	dw l03f8,l03ec,l03b8
	db #05
	dw l043c,l042a,l0404
	db #ff,#8b,#14,#80,#80,#80,#80,#85
.l04d8 equ $ + 2
.l04d6
	db #89,#00,#b0,#86,#02,#02,#c7,#e1
	db #8b,#14,#0c,#8b,#04,#0c,#8b,#14
	db #10,#8a,#0c,#13,#8b,#04,#0c,#8a
	db #15,#8a,#0c,#8b,#14,#16,#8b,#04
	db #0c,#8b,#14,#15,#8a,#0c,#13,#8b
	db #04,#0c,#8a,#10,#8a,#0c,#85
.l0505
	db #8b,#14,#11,#8b,#04,#11,#8b,#14
	db #15,#8a,#11,#18,#8b,#04,#11,#8a
	db #1a,#8a,#11,#8b,#14,#1b,#8b,#04
	db #11,#8b,#14,#1a,#8a,#11,#18,#8b
	db #04,#11,#8a,#15,#8a,#11,#85
.l052c
	db #89,#00,#c1,#b0,#86,#01,#01,#e1
	db #84,#2d,#2e,#e3,#2d,#2b,#e1,#84
	db #2c,#e3,#2e,#e1,#2e,#e3,#2d,#2b
	db #e1,#2d,#e3,#2b,#e7,#28,#c3,#b4
	db #e1,#35,#35,#34,#e3,#35,#e1,#34
	db #e3,#34,#e1,#34,#34,#34,#b0,#c1
	db #e1,#84,#2d,#2e,#e3,#2d,#2b,#e1
	db #2d,#e3,#2e,#e1,#2e,#e3,#2d,#2b
	db #e1,#2d,#e3,#2b,#e7,#28,#c3,#e1
	db #24,#24,#24,#e3,#26,#e1,#24,#e3
	db #24,#e1,#24,#24,#24,#e1,#33,#33
	db #e3,#32,#30,#e1,#32,#e3,#33,#e1
	db #33,#e3,#32,#30,#e1,#84,#2d,#ef
	db #30,#c3,#b4,#e1,#36,#37,#34,#35
	db #e9,#37,#85
.l059f
	db #89,#00
.l05a1
	db #c8,#86,#01,#02,#e1,#b1,#24,#24
	db #24,#24,#24,#24,#24,#24,#b2,#24
	db #24,#24,#24,#24,#24,#24,#24,#b1
	db #24,#24,#24,#24,#24,#24,#24,#24
	db #b3,#24,#24,#24,#24,#24,#24,#24
	db #24,#29,#29,#29,#29,#29,#29,#29
	db #29,#29,#29,#29,#29,#29,#29,#29
	db #29,#b1,#24,#24,#24,#24,#24,#24
	db #24,#24,#b3,#24,#24,#24,#24,#24
	db #24,#24,#24,#2b,#2b,#2b,#2b,#2b
	db #2b,#2b,#2b,#29,#29,#29,#29,#29
	db #29,#29,#29,#24,#24,#24,#24,#24
	db #24,#24,#24,#ef,#24,#89,#ff,#85
.l0609
	db #e1,#8b,#04,#13,#8a,#13,#8b,#14
	db #17,#8b,#04,#13,#8a,#1a,#8a,#13
	db #8b,#14,#1c,#8b,#04,#13,#8a,#11
	db #8a,#11,#8b,#14,#15,#8b,#04,#11
	db #8a,#18,#8a,#11,#8b,#14,#1a,#8b
	db #04,#11,#8a,#0c,#8a,#0c,#8a,#10
	db #8a,#0c,#8a,#11,#8a,#0c,#8a,#12
	db #8a,#0c,#8b,#14,#13,#10,#11,#e3
	db #13,#e1,#10,#0e,#0d,#89,#ff,#85
.l0651
	db #89,#00,#e1,#c2,#b0,#2f,#32,#33
	db #2f,#32,#33,#2f,#32,#33,#2f,#32
	db #33,#2f,#32,#33,#2f,#32,#33,#2f
	db #32,#33,#2f,#32,#33,#2f,#32,#33
	db #2f,#32,#34,#2f,#32,#34,#2d,#30
	db #31,#2d,#30,#31,#2d,#30,#31,#2d
	db #30,#31,#2d,#30,#31,#2f,#32,#33
	db #2f,#32,#33,#2f,#32,#33,#2f,#32
	db #e9,#33,#e1,#2f,#33,#34,#2f,#33
	db #34,#2f,#33,#34,#2f,#33,#34,#2f
	db #33,#34,#2f,#32,#33,#2f,#32,#33
	db #2f,#32,#33,#ef,#2a,#89,#f4,#85
.l06b1
	db #c1,#86,#01,#02,#e1,#8b,#14,#b0
	db #17,#b5,#2f,#b0,#12,#b5,#2f,#b0
	db #15,#b5,#2d,#b0,#10,#b5,#2d,#b0
	db #0f,#b5,#27,#b0,#0b,#b5,#27,#b0
	db #12,#b5,#2a,#b0,#0d,#b5,#2a,#85
.l06d9
	db #c0,#86,#00,#01,#b0,#e3,#2f,#2a
	db #2d,#28,#e1,#b4,#27,#27,#23,#27
	db #e3,#2a,#25,#b0,#e3,#2f,#2a,#2d
	db #28,#e1,#b4,#27,#27,#23,#27,#2a
	db #29,#28,#27,#85
.l06fd
	db #89,#0c,#c4
.l0700
	db #86,#00,#01,#b4,#e3,#2a,#e1,#25
	db #2a,#e3,#28,#23,#e1,#2e,#2e,#2a
	db #2e,#e3,#31,#2c,#e3,#2a,#e1,#25
	db #2a,#e3,#28,#23,#e1,#2e,#2e,#2a
	db #2e,#31,#30,#2f,#2e,#85
.l0726
	db #e3,#c5,#87,#66,#87,#66,#87,#66
	db #87,#66,#e1,#c6,#87,#66,#87,#66
	db #87,#66,#87,#66,#87,#66,#87,#66
	db #87,#66,#87,#66,#85
.l0743
	db #89,#01
.l0745
	db #e1,#b0,#12,#b3,#2a,#b0,#0d,#b3
	db #2a,#b0,#12,#b3,#2a,#b0,#0d,#b3
	db #2a,#89,#00,#85
.l0759
	db #89,#00,#b0,#15,#b3,#2d,#b0,#10
	db #b3,#2d,#b0,#15,#b3,#2d,#b0,#10
	db #b3,#2d,#b0,#15,#b3,#2d,#b0,#10
	db #b3,#2d,#b0,#15,#b3,#2d,#2d,#2e
	db #b0,#17,#b3,#2f,#b0,#12,#b3,#2f
	db #b0,#17,#b3,#2f,#b0,#12,#b3,#2f
	db #b0,#17,#b3,#2f,#b0,#12,#b3,#2f
	db #b0,#17,#b3,#2f,#b0,#12,#b3,#2f
	db #85
.l079a
	db #c3,#b0,#86,#01,#02,#2d,#2e,#2f
	db #30,#31,#37,#31,#37,#ef,#31,#e1
	db #33,#33,#c2,#fb,#82,#01,#14,#32
	db #c0,#85
.l07b4
	db #e1,#c3,#b0,#2f,#2d,#2a,#2b,#2c
	db #34,#2c,#34,#2d,#34,#2d,#34,#e7
	db #2f,#e1,#2f,#2d,#2a,#2b,#2c,#34
	db #2c,#34,#2d,#34,#2d,#2a,#e7,#28
	db #85
.l07d5
	db #b0,#10,#b3,#28,#b0,#0b,#b3,#28
	db #b0,#10,#b3,#28,#b0,#0b,#b3,#28
	db #b0,#12,#b1,#23,#b0,#0b,#b1,#23
	db #b0,#10,#b3,#28,#b0,#0b,#b3,#28
	db #85

.game_name
	db "Mad Balls",0
.game_year
	db "1988",0
.game_publisher
	db "Ocean Software",0
.music_author
	db "Jason C. Brooke",0
.music_comment
	db "This music module is the copyright of Jas.C.Brooke. Prepare to die!",0

	read "music_end_v1_0.asm"
